function rotDis(name, type, vals, warpId) {
	var _val;
	if (type == 'checked') {
		_val = $("input[name='" + name + "']:checked").val();
	} else if (type == 'selected') {
		_val = $("select[name='" + name + "'] option:selected").text();
	}
	var _objs = $("#" + warpId + " :input");
	if (_val != null && fit(_val, vals)) {
		_objs.each(function() {
			$(this).removeAttr('disabled');
		});
		$("#" + warpId).show();
	}else{
		_objs.each(function() {
			$(this).attr('disabled', 'disabled');
		});
		$("#" + warpId).hide();
	}
}

function fit(curVal, tagVals) {
	for ( var j in tagVals) {
		if (curVal == tagVals[j])
			return true;
	}
	return false;
}

function curDate(element, type) {
	var d = new Date();
	var week, ndate;
	var years = d.getFullYear();
	var month = d.getMonth() + 1;
	var days = d.getDate();
	if (type != undefined && type == "full") {
		switch (d.getDay()) {
		case 1:
			week = "星期一";
			break;
		case 2:
			week = "星期二";
			break;
		case 3:
			week = "星期三";
			break;
		case 4:
			week = "星期四";
			break;
		case 5:
			week = "星期五";
			break;
		case 6:
			week = "星期六";
			break;
		default:
			week = "星期天";
		}
		$(element).html(years + "年" + month + "月" + days + "日 " + " " + week);
	} else {
		$(element).val(years + "-" + month + "-" + days);
	}
}

var highlightcolor = '#eafcd5';
var clickcolor = '#51b2f6';
function changeto() {
	source = event.srcElement;
	if (source.tagName == "TR" || source.tagName == "TABLE")
		return;
	while (source.tagName != "TD")
		source = source.parentElement;
	source = source.parentElement;
	cs = source.children;
	{
		if (cs[1].style.backgroundColor != highlightcolor && source.id != "nc"
				&& cs[1].style.backgroundColor != clickcolor)
			for (i = 0; i < cs.length; i++) {
				cs[i].style.backgroundColor = highlightcolor;
			}
	}
}
function changeback() {
	if (event.fromElement.contains(event.toElement)
			|| source.contains(event.toElement) || source.id == "nc")
		return;
	if (event.toElement != source && cs[1].style.backgroundColor != clickcolor) {// source.style.backgroundColor=originalcolor
		for (i = 0; i < cs.length; i++) {
			cs[i].style.backgroundColor = "";
		}
	}
}

function mmgh2kpa(value, element) {
	value = value * 4 / 30;
	$("input[name='" + element + "']").val(value.toFixed(3));
}
function kpa2mmgh(value, element) {
	value = value * 30 / 4;
	$("input[name='" + element + "']").val(value.toFixed(3));
}

/** 使FireFox、Chrome等浏览器兼容selectSingleNode/selectNodes */
function adjustToFireFox() {
	if (document.implementation.hasFeature("XPath", "3.0")) {
		// prototying the XMLDocument
		XMLDocument.prototype.selectNodes = function(cXPathString, xNode) {
			if (!xNode) {
				xNode = this;
			}
			// name space resolver defined
			function nsResolver(prefix) {
				var ns = {
					'csw' : 'http://www.opengis.net/cat/csw',
					'smmd' : 'http://data.sbsm.gov.cn/smmd/2007'
				}; // 根据需要定制XML命名空间
				return ns[prefix] || null;
			}
			// var NSResolver =
			// this.createNSResolver(this.documentElement||this.ownerDocument.documentElement);
			var aItems = this.evaluate(cXPathString, xNode, nsResolver,
					XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
			var aResult = [];
			for ( var i = 0; i < aItems.snapshotLength; i++) {
				aResult[i] = aItems.snapshotItem(i);
			}
			return aResult;
		};

		// prototying the Element
		Element.prototype.selectNodes = function(cXPathString) {
			if (this.ownerDocument.selectNodes) {
				return this.ownerDocument.selectNodes(cXPathString, this);
			} else {
				throw "For XML Elements Only";
			}
		};

	}
	if (document.implementation.hasFeature("XPath", "3.0")) {
		// prototying the XMLDocument
		XMLDocument.prototype.selectSingleNode = function(cXPathString, xNode) {
			if (!xNode) {
				xNode = this;
			}
			var xItems = this.selectNodes(cXPathString, xNode);
			if (xItems.length > 0) {
				return xItems[0];
			} else {
				return null;
			}
		};

		// prototying the Element
		Element.prototype.selectSingleNode = function(cXPathString) {
			if (this.ownerDocument.selectSingleNode) {
				return this.ownerDocument.selectSingleNode(cXPathString, this);
			} else {
				throw "For XML Elements Only";
			}
		};
	}
}